package model

import (
	"time"
)

// City 城市管理模型
type City struct {
	ID           uint      `gorm:"primaryKey;autoIncrement" json:"id"`
	Name         string    `gorm:"type:varchar(100);not null;uniqueIndex:idx_name" json:"name"`
	Code         string    `gorm:"type:varchar(50)" json:"code"`
	ProvinceID   uint      `gorm:"index:idx_province_id" json:"province_id"`
	ProvinceName string    `gorm:"type:varchar(100)" json:"province_name"`
	Status       int       `gorm:"default:1;index:idx_status" json:"status"`
	Sort         int       `gorm:"default:0;index:idx_sort" json:"sort"`
	CreatedAt    time.Time `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt    time.Time `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt    time.Time `gorm:"index" json:"-"`
}

// TableName 指定表名
func (City) TableName() string {
	return "city"
}

// CityQueryParams 城市查询参数
type CityQueryParams struct {
	Page         int    `form:"page" json:"page"`
	PageSize     int    `form:"page_size" json:"page_size"`
	Name         string `form:"name" json:"name"`
	ProvinceName string `form:"province_name" json:"province_name"`
	Status       *int   `form:"status" json:"status"`
	SortBy       string `form:"sort_by" json:"sort_by"`
	Order        string `form:"order" json:"order"`
}

// CityCreateRequest 创建城市请求
type CityCreateRequest struct {
	Name         string `json:"name" binding:"required,max=100"`
	Code         string `json:"code" binding:"max=50"`
	ProvinceID   uint   `json:"province_id"`
	ProvinceName string `json:"province_name" binding:"max=100"`
	Status       int    `json:"status" binding:"min=0,max=1"`
	Sort         int    `json:"sort"`
}

// CityUpdateRequest 更新城市请求
type CityUpdateRequest struct {
	Name         string `json:"name" binding:"max=100"`
	Code         string `json:"code" binding:"max=50"`
	ProvinceID   uint   `json:"province_id"`
	ProvinceName string `json:"province_name" binding:"max=100"`
	Status       int    `json:"status" binding:"min=0,max=1"`
	Sort         int    `json:"sort"`
}